package com.sunxd.vue.application.facade.impl;

import com.sunxd.vue.application.facade.UserFacade;
import com.sunxd.vue.bean.Response;
import com.sunxd.vue.bean.request.UserPageReq;
import com.sunxd.vue.bean.request.UserReq;
import com.sunxd.vue.bean.request.UserUpdateReq;
import com.sunxd.vue.bean.response.UserVo;
import com.sunxd.vue.domain.bean.assembler.UserAssembler;
import com.sunxd.vue.domain.service.UserService;
import com.sunxd.vue.infrastructure.adapter.db.base.Paging;
import com.sunxd.vue.infrastructure.utils.PagingUtil;
import com.sunxd.vue.infrastructure.utils.ResponseHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import static com.sunxd.vue.infrastructure.utils.ResponseHelper.or500;

/**
 * @author sun.xd
 * @description: description
 * @date 2024/4/2 10:50
 */
@Service
@RequiredArgsConstructor
public class UserFacadeImpl implements UserFacade {

    private final UserService userService;

    public Response<Boolean> create(UserReq req){
        return or500(() -> userService.create(req));
    }

    @Override
    public Response<Boolean> update(UserUpdateReq req) {
        return or500(() -> userService.update(req));
    }

    @Override
    public Response<Paging<UserVo>> page(UserPageReq req) {
        return  or500(() -> PagingUtil.toPaging(userService.page(req),UserAssembler.CONVERTER::do2vo));
    }

    @Override
    public Response<UserVo> detail(UserReq req) {
        return or500(()->userService.findOne(UserAssembler.CONVERTER.req2do(req)),UserAssembler.CONVERTER::do2vo);
    }

    @Override
    public Response<Boolean> testTran(UserReq req) {
        return or500(() -> userService.testTran(req));
    }
}
